import {checkIPhoneX} from '../components/wux/helpers/checkIPhoneX';
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const NP = require('number-precision')

// 校验手机号
const checkPhone = phone => {
  let check = /^1[3|4|5|6|7|8|9][0-9]{9}$/
  return check.test(phone)
}

// 解析 scene 值，返回参数对象
const parseQuery = (scene) => {
  // 解码
  let decodeScene = decodeURIComponent(scene)
  // 去掉问号
  let query = decodeScene.substr(1, decodeScene.length)
  // 转换成对象返回
  var args = {};
  var items = query.split("&");

  var item = null, name = null, value = null;
  for(var i=0; i < items.length; i++){
      item = items[i].split("=");
      if(item[0]){
          name = item[0];
          value = item[1] ? item[1] : "";
          args[name] = value;
      }
  }
  return args;
}

module.exports = {
  formatTime: formatTime,
  NP,
  checkPhone,
  parseQuery
}
